package gov.gfbzb.advice.serviceImpl;

import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.rag.content.retriever.EmbeddingStoreContentRetriever;
import dev.langchain4j.service.AiServices;
import gov.gfbzb.advice.config.DocumentEmbeddingConfig;
import gov.gfbzb.advice.service.IAiService;
import gov.gfbzb.advice.service.IChatService;
import jakarta.annotation.Resource;
import lombok.extern.log4j.Log4j2;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.concurrent.CompletableFuture;

/**
 * chat服务
 */
@Log4j2
@Service
public class ChatServiceImpl implements IChatService {

    // 注入聊天模型
    @Resource
    private ChatLanguageModel chatLanguageModel;

    @Async("deepSeekExecutor")
    public CompletableFuture<String> advice(String message) {
        IAiService assistant = AiServices.builder(IAiService.class)
                .chatLanguageModel(chatLanguageModel)
                .contentRetriever(EmbeddingStoreContentRetriever.from(DocumentEmbeddingConfig.embeddingStore))
                .build();
        String chat = assistant.chat(message);
        return CompletableFuture.completedFuture(chat);
    }
}
